const mongoose = require("mongoose");


const orderSchema = new mongoose.Schema(
    {
        user_id: {
            type: mongoose.Schema.Types.ObjectId,
            ref: "userModel"
        },
        goods_id: {
            type: mongoose.Schema.Types.ObjectId,
            ref: "goodsModel"
        },
        total: {
            type: Number,
            default: 1
        },
        sum: {
            type: Number,
            default: 0
        },
        //0-删除，1-未发货，2-已发货，3-已取消
        status: {
            type: Number,
            default: 1
        },
        is_delete: {
            type: Number,
            default: 1
        },
        remark: {
            type: String
        },
        //创建订单默认时间
        date: {
            type: Date,
            default: Date.now, //设置创建订单默认时间,传入函数
            get(val){
                return new Date(val).toLocaleString()
            }
        }
    },
    { versionKey: false } //去除__v标识
);
//设置模型

orderSchema.set('toJSON', { getters: true });

const Model = mongoose.model("order", orderSchema);

module.exports = Model;
